package com.sojson.project.service.impl;

import java.sql.SQLException;
import java.util.ArrayList;
import java.util.List;

import javax.annotation.Resource;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.sojson.project.dao.SpecsCateDao;
import com.sojson.project.entity.po.SpecsAttr;
import com.sojson.project.entity.po.SpecsCate;
import com.sojson.project.service.SpecsAttrService;
import com.sojson.project.service.SpecsCateService;
import com.sojson.util.ExpUtil;

/**
 * 规格表Service实现类
 * 
 * @author liu
 * @date 2021-03-22
 */
@Service
public class SpecsCateServiceImpl implements SpecsCateService {

    @Autowired
    private SpecsAttrService specsAttrService;
    @Resource
    private SpecsCateDao specsCateDaoImpl;

    /**
     * 单条插入
     * 
     * @param specsCate
     * @return
     * @throws SQLException
     */
    @Override
    public int insert(SpecsCate specsCate) {
        int insert = specsCateDaoImpl.insert(specsCate);
        return insert;
    }

    /**
     * 批量插入
     * 
     * @param specsCate
     * @return
     * @throws SQLException
     */
    @Override
    public int insertList(SpecsCate specsCate) {
        int insertList = specsCateDaoImpl.insertList(specsCate.getSpecsCates());
        return insertList;
    }

    /**
     * 通过对象批量删除(物理删除)
     * 
     * @param specsCate
     * @return
     * @throws SQLException
     */
    @Override
    public int deleteByDto(SpecsCate specsCate) {
        int deleteByDto = specsCateDaoImpl.deleteByDto(specsCate);
        return deleteByDto;
    }

    /**
     * 统计全部数量
     * 
     * @return
     * @throws SQLException
     */
    @Override
    public int countAll() {
        int countAll = specsCateDaoImpl.countAll();
        return countAll;
    }

    /**
     * 查询所有
     * 
     * @return
     * @throws SQLException
     */
    @Override
    public List<SpecsCate> findAll() {
        List<SpecsCate> findAll = specsCateDaoImpl.listAll();
        return findAll;
    }

    /**
     * 根据对象统计数量
     * 
     * @param specsCate
     * @return
     * @throws SQLException
     */
    @Override
    public int countByDto(SpecsCate specsCate) {
        int countByDto = specsCateDaoImpl.countByDto(specsCate);
        return countByDto;
    }

    /**
     * 根据对象查询
     * 
     * @param specsCate
     * @return
     * @throws SQLException
     */
    @Override
    public List<SpecsCate> findByDto(SpecsCate specsCate) {
        List<SpecsCate> findByDto = specsCateDaoImpl.listByDto(specsCate);
        return findByDto;
    }

    /**
     * 通过id删除(物理删除)
     * 
     * @param id
     * @return
     * @throws SQLException
     */
    @Override
    public int deleteById(Integer id) {
        SpecsAttr specsAttr = new SpecsAttr();
        specsAttr.setSpecsCateId(id);
        int countByDto = specsAttrService.countByDto(specsAttr);
        if (countByDto > 0) {
            ExpUtil.throwEx("规格分组下存在规格明细,请先删除规格明细");
        }
        int deleteById = specsCateDaoImpl.deleteById(id);
        return deleteById;
    }

    /**
     * 通过id列表删除(物理删除)
     * 
     * @param ids
     * @return
     * @throws SQLException
     */
    @Override
    public int deleteByIdList(ArrayList<Integer> ids) {
        int deleteByIdList = specsCateDaoImpl.deleteByIdList(ids);
        return deleteByIdList;
    }

    /**
     * 通过id更新(全部更新)
     * 
     * @param specsCate
     * @return
     * @throws SQLException
     */
    @Override
    public int updateById(SpecsCate specsCate) {
        int updateById = specsCateDaoImpl.updateById(specsCate);
        return updateById;
    }

    /**
     * 通过id列表更新(全部更新)(更新内容相同)
     * 
     * @param specsCate
     * @return
     * @throws SQLException
     */
    @Override
    public int updateStaticByIdList(SpecsCate specsCate) {
        int updateStaticByIdList = specsCateDaoImpl.updateStaticByIdList(specsCate);
        return updateStaticByIdList;
    }

    /**
     * 通过id列表更新(全部更新)(更新内容不相同)
     * 
     * @param specsCate
     * @return
     * @throws SQLException
     */
    @Override
    public int updateChangeByIdList(SpecsCate specsCate) {
        int updateChangeByIdList = specsCateDaoImpl.updateChangeByIdList(specsCate.getSpecsCates());
        return updateChangeByIdList;
    }

    /**
     * 通过id更新(局部更新)
     * 
     * @param specsCate
     * @return
     * @throws SQLException
     */
    @Override
    public int updatePartialById(SpecsCate specsCate) {
        int updatePartialById = specsCateDaoImpl.updatePartialById(specsCate);
        return updatePartialById;
    }

    /**
     * 通过id列表更新(局部更新)(更新内容相同)
     * 
     * @param specsCate
     * @return
     * @throws SQLException
     */
    @Override
    public int updateStaticPartialByIdList(SpecsCate specsCate) {
        int updateStaticPartialByIdList = specsCateDaoImpl.updateStaticPartialByIdList(specsCate);
        return updateStaticPartialByIdList;
    }

    /**
     * 通过id列表更新(局部更新)(更新内容不相同)
     * 
     * @param specsCate
     * @return
     * @throws SQLException
     */
    @Override
    public int updateChangePartialByIdList(SpecsCate specsCate) {
        int updateChangePartialByIdList = specsCateDaoImpl.updateChangePartialByIdList(specsCate.getSpecsCates());
        return updateChangePartialByIdList;
    }

    /**
     * 通过id查询
     * 
     * @param id
     * @return
     * @throws SQLException
     */
    @Override
    public SpecsCate findById(Integer id) {
        SpecsCate findById = specsCateDaoImpl.findById(id);
        return findById;
    }

    /**
     * 通过id列表查询
     * 
     * @param ids
     * @return
     * @throws SQLException
     */
    @Override
    public ArrayList<SpecsCate> findByIdList(ArrayList<Integer> ids) {
        ArrayList<SpecsCate> findByIdList = specsCateDaoImpl.findByIdList(ids);
        return findByIdList;
    }

    /**
     * 通过对象查询id列表
     * 
     * @param specsCate
     * @return
     * @throws SQLException
     */
    @Override
    public ArrayList<Integer> findIdByDto(SpecsCate specsCate) {
        ArrayList<Integer> findIdByDto = specsCateDaoImpl.findIdByDto(specsCate);
        return findIdByDto;
    }

    /**
     * 清空数据(物理清空)
     * 
     * @throws SQLException
     */
    @Override
    public void clear() {
        specsCateDaoImpl.clear();
    }

    /**
     * 根据对象查询
     * 
     * @param specsCate
     * @return
     * @throws SQLException
     */
    @Override
    public List<SpecsCate> list(SpecsCate specsCate) {
        return specsCateDaoImpl.list(specsCate);
    }

    /**
     * 通过id查询(包含商品规格明细)
     * 
     * @param id
     * @return
     * @throws SQLException
     */
    @Override
    public SpecsCate getInfo(Integer id) {
        return specsCateDaoImpl.getInfo(id);
    }

}